#ifndef FSPHENIX_MCAPP_H
#define FSPHENIX_MCAPP_H

#include <TVirtualMCApplication.h>
#include "TMCVerbose.h"

#include "sPHENIX_DetectorConstruction.h"
#include "sPHENIX_EMCalSD.h"
#include "sPHENIX_GEMSD.h"
#include "sPHENIX_PreshowerSD.h"
#include "sPHENIX_HCalSD.h"
#include "sPHENIX_RootManager.h"
#include "sPHENIX_MagField.h"

//class TVirtualMagField;

class sPHENIX_MCStack;

class sPHENIX_MCApplication : public TVirtualMCApplication {
 public :
  sPHENIX_MCApplication(const char *name, 
			const char* title, 
			Int_t nOfEvents,			
			FileMode fileMode = kWrite);
  sPHENIX_MCApplication();
  ~sPHENIX_MCApplication();

  static sPHENIX_MCApplication* Instance();

  // methods
  void InitMC(const char *setup);
  void RunMC();
  void FinishRun();
  void SetInputFile(const char *in_file);

  virtual void ConstructGeometry();
  virtual void InitGeometry();
  virtual void GeneratePrimaries();
  virtual void BeginEvent();
  virtual void BeginPrimary();
  virtual void PreTrack();
  virtual void Stepping();
  virtual void PostTrack();
  virtual void FinishPrimary();
  virtual void FinishEvent();

  void   ReadEvent(Int_t i);

  // method for tests
  void SetOldGeometry(Bool_t oldGeometry = kTRUE);

 private :
  // methods
  void RegisterStack();

  // data members
  sPHENIX_MCStack *Stack;
  sPHENIX_DetectorConstruction* DetConstruction;
  sPHENIX_EMCalSD*              EMCalSD;
  sPHENIX_GEMSD*                GEMSD;
  sPHENIX_PreshowerSD*          PreshowerSD;
  sPHENIX_HCalSD*               HCalSD;
  sPHENIX_RootManager           RootManager;
  sPHENIX_MagField*             MagField;
  Int_t                         NofEvents;

  string input_file;
  int use_input_file;
  int event_number;
  TTree *input_tree;
  //vector<TParticle*> input_part_list;
  vector<TParticle*> *input_part_list_ptr;

  ClassDef(sPHENIX_MCApplication,1);
};

inline sPHENIX_MCApplication* sPHENIX_MCApplication::Instance() {
  return (sPHENIX_MCApplication*)(TVirtualMCApplication::Instance());
}

#endif
